<?php
namespace Menu\Model;
use Think\Model;
class PhotosModel extends Model {
	public function PhotoAdd(){
		$data = $this->create();
		$photo_url = $this->upload();
		$data['photo_url'] = $photo_url;
		$data['addtime']   = time();
		if($this->add($data)){
			$msg['info'] = "添加照片成功";
			$msg['number'] = 1;
		}
		return $msg;
	}

	public function upload(){
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     3145728 ;// 设置附件上传大小
		$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->rootPath  =      './Public'; // 设置附件上传根目录
		$upload->savePath  =      './Uploads/'; // 设置附件上传（子）目录
		//上传单个文件 
		$info   =   $upload->uploadOne($_FILES['photo_url']);
		if(!$info) {
			// 上传错误提示错误信息
			$this->error($upload->getError());
		}else{
			//上传成功 获取上传文件信息
			$photo_cover =  '/Public'.ltrim($info['savepath'].$info['savename'],'.');
			return $photo_cover;
		}
	}

	public function photoList($album_id){
		$data = $this
		->field('photo_name,Jenson_photos.addtime,photo_url,album_name')
		->join('RIGHT JOIN Jenson_album ON Jenson_photos.album_id = Jenson_album.album_id')
		->where("Jenson_album.album_id =$album_id")
		->select();
		return $data;
	}
}